//////variable definitions.
//////variables.
keep weight4 w1consp1-w1consp4 w4consp1-w4consp4 w4cn1-w4cn5 age income gender degree race ///
w1amer1 w1trust1-w1trust5 w1civk1-w1civk4 w1ideo1 w1auth1-w1auth4 w1ncc1-w1ncc6

///wave 1 conspiracies.
egen rconsp1=rmean(w1consp1-w1consp4)
recode01 rconsp1
rename rconsp101 rconsp011

///wave 4 conspiracies.
egen rconsp4=rmean(w4consp1-w4consp4)
recode01 rconsp4
rename rconsp401 rconsp014

///collective narcissism
gen rcn1=(w4cn1-1)/6
gen rcn2=(w4cn2-1)/6
gen rcn3=(w4cn3-1)/6
gen rcn4=(w4cn4-1)/6
gen rcn5=(w4cn5-1)/6
egen rcnsc=rmean(rcn1 rcn2 rcn3 rcn4 rcn5)
rename rcnsc rcnsc4

///age, recoded.
recode01 age

///income, recoded.
recode01 income

///gender (as is)

///education, recoded.
gen educ=degree
recode01 educ

///race indicator.
gen white=1 if race==4
replace white=0 if race~=4

///american identification.
recode w1amer1 (1=1) (2=0), generate(amerid1)

///social trust.
gen tr11=(4-w1trust1)/3
gen tr21=(4-w1trust2)/3
gen tr31=(4-w1trust3)/3
gen tr41=(4-w1trust4)/3
gen tr51=(4-w1trust5)/3
egen trscal1=rmean(tr11 tr21 tr31 tr41 tr51)

///political knowledge.
gen kn11=1 if w1civk1==1
replace kn11=0 if w1civk1~=1
gen kn21=1 if w1civk2==2
replace kn21=0 if w1civk2~=2
gen kn31=1 if w1civk3==4
replace kn31=0 if w1civk3~=4
gen kn41=1 if w1civk4==1
replace kn41=0 if w1civk4~=1
egen knscal011=rmean(kn11-kn41)

///ideology.
gen ideo=w1ideo1
recode01 ideo
rename ideo01 ideo011

///ideological extremity.
gen idex1=abs(ideo011-.5)
recode01 idex1

///authoritarianism.
gen aut1=1 if w1auth1==2
replace aut1=0 if w1auth1==1 
gen aut2=1 if w1auth2==1
replace aut2=0 if w1auth2==2 
gen aut3=1 if w1auth3==2
replace aut3=0 if w1auth3==1 
gen aut4=1 if w1auth4==2
replace aut4=0 if w1auth4==1 
egen rauth=rmean(aut1 aut2 aut3 aut4)
rename rauth rauth1

///need for closure.
egen rnfc=rmean(w1ncc1-w1ncc6)
recode01 rnfc
rename rnfc01 rnfc011

//////set weight.
svyset [pweight=weight4]

//////Table 1: correlations.
///using only Rs with complete data:
egen rmiss=rowmiss(rconsp014 rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011)
pwcorr rconsp014 rconsp011 rcnsc4 amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011 [aweight=weight4] if rmiss==0, sig
///Diff. b/w coefficients for correlations b/w CN and CT at T1 (r = .09, p<.001) and b/w CN and CT at T2 (r = .24, p<.001):
///Steiger's Z = 6.381, p<0.001
///Computed using http://quantpsy.org/corrtest/corrtest2.htm

//////Table 2: Change over time - wave 1 to wave 4.
///Model 1: CN + lagged DV 
svy: reg rconsp014 rconsp011 rcnsc4
local y rconsp014  
local xvars rconsp011 rcnsc4
quietly svy: reg `y' `xvars'
	quietly matrix b = e(b)
quietly svy: mean `y'
    quietly estat sd
    quietly matrix sy = r(sd)
quietly svy: mean `xvars'
    quietly estat sd
    quietly matrix sx = r(sd)
quietly mata:
     sy = st_matrix("sy")
     sx = st_matrix("sx")'
     b = st_matrix("b")
     bx = b[1 ,1..(cols(b)-1)]'
     st_matrix("betas",(sx:/sy):*bx)
    end
quietly matrix rownames betas = `xvars'
matrix list betas

///Model 2: CN + lagged DV + controls.
svy: reg rconsp014 rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011
margins, at(rcnsc4=(0 1))
quietly margins, at(amerid1=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("American ID", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct0a, replace)
quietly margins, at(trscal1=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Trust", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1a, replace)
quietly margins, at(knscal011=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Information", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1b, replace)	
quietly margins, at(ideo011=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideology", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1c, replace)	
quietly margins, at(idex101=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideological Extremity", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1d, replace)	
quietly margins, at(rauth1=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Authoritarianism", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1e, replace)
quietly margins, at(rnfc011=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Need for Closure", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1f, replace)	
quietly margins, at(rcnsc4=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Collective Narcissism", color(black) size(vlarge)) ///
	xtitle("") ytitle("Change in Conspiratorial Thinking") saving (ct1g, replace)	
graph combine ct0a.gph ct1a.gph ct1b.gph ct1c.gph ct1d.gph ct1e.gph ct1f.gph ct1g.gph, ///
	cols(4) altshrink ycommon xsize(4) ysize(2) graphr(color(white)) saving(ct1, replace)	

svy: reg rconsp014 rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011
local y rconsp014  
local xvars rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011
quietly svy: reg `y' `xvars'
	quietly matrix b = e(b)
quietly svy: mean `y'
    quietly estat sd
    quietly matrix sy = r(sd)
quietly svy: mean `xvars'
    quietly estat sd
    quietly matrix sx = r(sd)
quietly mata:
     sy = st_matrix("sy")
     sx = st_matrix("sx")'
     b = st_matrix("b")
     bx = b[1 ,1..(cols(b)-1)]'
     st_matrix("betas",(sx:/sy):*bx)
    end
quietly matrix rownames betas = `xvars'
matrix list betas	
	
//////Robustness check: CN x ideology interaction (Footnote 1).
svy: reg rconsp014 rconsp011 c.rcnsc4 age01 income01 gender educ01 white amerid1 c.trscal1 c.knscal011 c.ideo011 c.idex101 c.rauth1 c.rnfc011 c.rcnsc4#c.ideo011
margins, dydx(c.rcnsc4) at(ideo011=(0 (.2) 1))

//////Errors-in-variables model (Table A2):
svy: sem (rconsp011 <- Rconsp1) ///
		 (rcnsc4 <- Rcnsc4) ///
	     (trscal1 <- Trscal1) ///
		 (knscal011 <- Knscal1) ///
		 (rauth1 <- Rauth1) ///
		 (rnfc011 <- Rnfc011) ///
	     (rconsp014 <- age01 income01 gender educ01 white amerid1 ideo011 idex101) ///
		 (rconsp014 <- Rconsp1) (rconsp014 <- Rcnsc4) (rconsp014 <- Trscal1) ///
		 (rconsp014 <- Knscal1) (rconsp014 <- Rauth1) (rconsp014 <- Rnfc011), ///
		 reliability (rconsp011 .82 rcnsc4 .83 trscal1 .75 knscal011 .55 rauth1 .61 rnfc011 .86)
estat gof, stats(chi2 rmsea res indices)
estat eqgof

//////mplus file.
ssc install stata2mplus 
keep rconsp014 rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011 weight4
recode rconsp014 rconsp011 rcnsc4 age01 income01 gender educ01 white amerid1 trscal1 knscal011 ideo011 idex101 rauth1 rnfc011 weight4(.=-9999)
rename rconsp014 rcp014
rename rconsp011 rcp011
rename knscal011 kns011
stata2mplus using lcsmcn2
///To convert the file to mplus, start mplus and run the file lcsmcn2.inp

	